package cn.edu.hqu.javaee;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import cn.edu.hqu.javaee.domain.Course;
import cn.edu.hqu.javaee.domain.Course.Type;
import cn.edu.hqu.javaee.domain.User;
import cn.edu.hqu.javaee.repository.CourseRepository;
import cn.edu.hqu.javaee.repository.UserRepository;



@SpringBootApplication
public class CourseSql2Application {

	public static void main(String[] args) {
		SpringApplication.run(CourseSql2Application.class, args);
	}
	
	@Bean
	public CommandLineRunner dataLoader(CourseRepository courseRepo, UserRepository userRepo) {
		return new CommandLineRunner() {
			@Override
			public void run(String... args) throws Exception {
				courseRepo.save(new Course("数学1", "高等数学", Type.BASICS));
				courseRepo.save(new Course("数学2", "离散数学", Type.BASICS));
				courseRepo.save(new Course("数学3", "随机数学", Type.BASICS));
				courseRepo.save(new Course("数学4", "高等代数", Type.BASICS));
				courseRepo.save(new Course("设计1", "c++设计", Type.MAJOR));
				courseRepo.save(new Course("设计2", "java设计", Type.MAJOR));
				courseRepo.save(new Course("设计3", "python设计", Type.MAJOR));
				courseRepo.save(new Course("设计4", "java web设计", Type.MAJOR));
				courseRepo.save(new Course("软件1", "软件建模与分析", Type.THEORY));
				courseRepo.save(new Course("软件2", "软件工程", Type.THEORY));
				courseRepo.save(new Course("软件3", "软件开发标准与文档", Type.THEORY));
				BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
				User user1 = new User("涂涂", encoder.encode("123"), "13829150519");
				userRepo.save(user1);

			}

		};
	}
}
